import 'muse-ui/dist/muse-ui.css'
import 'babel-polyfill'
import Vue from 'vue'
import VueLazyload from 'vue-lazyload'
import App from './App'
import router from './router'
import store from './vuex/store'
import MuseUI from 'muse-ui'
import {GetRequest} from './common/js/util'
import VueWechatTitle from 'vue-wechat-title'
import errorImg from './assets/head_images.png'

Vue.use(VueWechatTitle)

MuseUI.config({
  disableTouchRipple: false,
  disableFocusRipple: true
})
Vue.use(MuseUI)
Vue.use(VueLazyload, {
  error: errorImg
})
// Mock server for devolopment
// import Mock from './mock'
// Mock.start()

// Navigation Guards -check logined or not
router.beforeEach((to, from, next) => {
  if (GetRequest(to.fullPath).openId !== undefined) {
    localStorage.openId = GetRequest(to.fullPath).openId
  }
  if (to.matched.some(record => record.meta.requiresAuth)) {
    if (localStorage.accessToken) {
      next()
    } else {
      next({
        path: '/login',
        query: { redirect: to.fullPath }
      })
    }
  } else {
    next()
  }
})

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
